package com.innovate.nms.service.channel;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;

import com.google.common.eventbus.AsyncEventBus;

import lombok.Getter;


public abstract class Channel {
	
	/*
	 * EVENT SUPPORT
	 */	
	public static AsyncEventBus eventbus = 
			new AsyncEventBus("ChannelEventBus", Executors.newSingleThreadExecutor());
	
	/*
	 * CHANNEL MANAGER
	 */
	protected static Map<String, Channel> map = 
			new HashMap<String, Channel>();
	
	public static Channel getChannel(String key) {
		return map.get(key);
	}
	
	public static boolean isChannelReady(String key) {
		Channel c = map.get(key);
		if(c != null) {
			return c.isReady();
		} else {
			return false;
		}
	}
	
	
	/*
	 * MEMBERS
	 */
	@Getter
	protected String key;	
	
	public Channel(String key) {
		super();
		this.key = key;
		map.put(key, this);
		System.out.println("Channel " + key + " created.");
	}
	

	/**
	 * ��ȡͨ��Ӧ��ʱ��ʱ�䣬��λ����
	 */
	public abstract int getTimeout();

	/**
	 * ���ͨ���Ƿ����
	 */
	public abstract boolean isReady();
	
	/**
	 * ͨ��ͨ����������
	 */
	public abstract void send(String target, String content) throws Exception;
	
	
}
